package com.example.myapplication.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.example.myapplication.R;
import com.example.myapplication.bases.BaseActivity;

/**
 * @author yuanc
 * @Description: (用一句话描述)
 * @date 2025/7/30 9:14
 */
public class HomeActivity extends BaseActivity {

    private Button btn_life;
    private Button btn_savestate;
    private Button btn_senddata;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        btn_life = findViewById(R.id.btn_life);
        btn_senddata = findViewById(R.id.btn_senddata);

        btn_life.setOnClickListener(clickListener);
        btn_senddata.setOnClickListener(clickListener);
    }


    private View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            if (v.getId() == R.id.btn_life) {
                Toast.makeText(HomeActivity.this, "请查看日志", Toast.LENGTH_SHORT).show();
            }
            if (v.getId() == R.id.btn_senddata) {
                intent.setClass(HomeActivity.this, ReceiveDataActivity.class);
                intent.putExtra("message","我是MainActivity的数据信息");
                // 跳转，且要求回传数据
                startActivityForResult(intent, 110);
            }
        }
    };

    // 回传数据回时，回调的方法
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (data != null) {
            // 取出回传数据
            String msg = data.getStringExtra("aaa");
            Toast.makeText(this, resultCode + " 回传信息回来了 " + msg, Toast.LENGTH_SHORT).show();
        }
    }
}
